package cn.youqu.happy.module.youqu.convert.userTell;

import cn.hutool.core.collection.CollUtil;
import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.module.youqu.controller.admin.userTell.vo.*;
import cn.youqu.happy.module.youqu.controller.app.userTell.vo.*;
import cn.youqu.happy.module.youqu.dal.dataobject.userTell.UserTellDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户说说 Convert
 *
 * @author 王其岩 20112001045
 */
@Mapper(componentModel = "spring")
public interface UserTellConvert {

    UserTellConvert INSTANCE = Mappers.getMapper(UserTellConvert.class);


    @Mapping(target = "img", source = "imgList")
    UserTellDO convert(UserTellCreateReqVO bean);

    @Mapping(target = "img", source = "imgList")
    UserTellDO convert(UserTellUpdateReqVO bean);


    @Mappings({
            @Mapping(target = "imgList", source = "img"),
            @Mapping(target = "partnerList", source = "partners")
    })
    UserTellRespVO convert(UserTellDO bean);

    @Mappings({
            @Mapping(target = "imgList", source = "img"),
            @Mapping(target = "partnerList", source = "partners")
    })
    AppUserTellRespVO convert0(UserTellDO bean);

    List<UserTellRespVO> convertList(List<UserTellDO> list);

    List<AppUserTellRespVO> convertList0(List<UserTellDO> list);

    PageResult<UserTellRespVO> convertPage(PageResult<UserTellDO> page);

    PageResult<AppUserTellRespVO> convertPage0(PageResult<UserTellDO> page);

    List<UserTellExcelVO> convertList02(List<UserTellDO> list);

    @Mapping(target = "img", source = "imgList")
    UserTellDO convert(AppUserTellCreateReqVO createReqVO);

    UserTellPageReqVO convert(AppUserTellPageReqVO pageVO);

    @Mapping(target = "img", source = "imgList")
    UserTellDO convert(AppUserTellPublishReqVO publishReqVO);

    @Mapping(target = "img", source = "imgList")
    UserTellDO convert(AppUserTellUpdateReqVO updateReqVO);

    default List<String> str2List(String src) {
        if (src == null || src.isEmpty()) return new ArrayList<>();
        String[] split = src.split(",");
        return Arrays.asList(split);
    }

    default String list2Str(List<String> src) {
        if (CollUtil.isEmpty(src)) {
            return "";
        }
        return String.join(",", src);
    }

    default String list2Str2(List<Long> src) {
        if (CollUtil.isEmpty(src)) {
            return "";
        }
        List<String> collect = src.stream().map(String::valueOf).collect(Collectors.toList());
        return String.join(",", collect);
    }


    default List<Long> str2List2(String src) {
        if (src == null || src.isEmpty()) return new ArrayList<Long>();
        String[] split = src.split(",");
        return Arrays.stream(split).map(Long::valueOf).collect(Collectors.toList());
    }

    UserTellPageReqVO convert(AppUserTellSquarePageReqVO pageReqVO);
}
